import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/Home.vue'

Vue.use(VueRouter)

const routes = [
   {
      path: '/',
      name: 'Home',
      component: () => import('../views/Home/Home.vue'),
      children: [
         {
            path: "/",
            name: "Main",
            component: () => import("../views/Home/Main.vue"),
            children: [
               {
                  path: "/",
                  name: "MainHome",
                  component: () => import("../views/Home/MainHome.vue")
               },
               {
                  path: "/photo",
                  name: "Photo",
                  component: () => import("../views/Home/Photo.vue")
               },
               {
                  path: "/list",
                  name: "List",
                  component: () => import("../views/Home/List.vue")
               }
            ]
         },
         {
            path: "/store",
            name: "Store",
            component: () => import("../views/Store/Store.vue"),
            children: [
               {
                  path: "/storehome",
                  name: "StoreHome",
                  component: () => import("../views/Store/StoreHome.vue")
               },
               {
                  path: "/storeclass",
                  name: "StoreClass",
                  component: () => import("../views/Store/StoreClass.vue")
               },
               {
                  path: "/store",
                  name: "StoreList",
                  component: () => import("../views/Store/StoreList.vue")
               }
            ]
         },
         {
            path: "/order",
            name: "Order",
            component: () => import("../views/Order/Order.vue"),
            children: [
               {
                  path: "/order1",
                  name: "OrderHome",
                  component: () => import("../views/Order/Order1.vue")
               },
               {
                  path: "/order2",
                  name: "Order2",
                  component: () => import("../views/Order/Order2.vue")
               },
               {
                  path: "/order3",
                  name: "Order3",
                  component: () => import("../views/Order/Order3.vue")
               }
            ]
         },
         {
            path: "/vip",
            name: "Vip",
            component: () => import("../views/Vip/Vip.vue")
         },
         {
            path: "/setting",
            name: "Setting",
            component: () => import("../views/Setting/Setting.vue"),
         }
      ]
   },
   {
      path: '/login',
      name: 'Login',
      component: () => import('../views/Login.vue')
   },
];


const router = new VueRouter({
   mode: 'history',
   base: process.env.BASE_URL,
   routes
});

// 路由首守卫
router.beforeEach((to, from, next) => {
   var userLogonStatus = localStorage.getItem("token");
   if (to.name !== "Login") {
      if (userLogonStatus) {
         next()
      } else {
         next("/login")
      }
   } else {
      next();
   }
});

export default router
